package com.hd.trans.utils;

import android.os.Build;
import android.os.Environment;

import com.hd.trans.ui.base.AppContextProvider;

import java.io.File;

/**
 * Author:  yang
 * Date:  2020-01-15 01:43
 * Desc:  照片工具类(路径)
 */
public final class PhotoFileUtil {

    /*** 拍照--照片存储路径(bitmap存图片) */
    private static final String PHOTO_ORIG_PATH = "SDK/Photos/Orig/";

    /*** 压缩保存路径 */
    private static final String PHOTO_TARGET_PATH = "SDK/Photos/Target/";

    /*** 从服务器下载的图片保存路径 */
    private static final String PHOTO_DOWNLOAD_PATH = "SDK/Photos/Download/";

    public static String getCacheRoot(){
        String path;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            path = AppContextProvider.getContext().getFilesDir().getAbsolutePath() + "/";
        }else {
            path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
        }
        return path;
    }

    public static String getPhotoOrigPath() {
        String path = getCacheRoot() + PHOTO_ORIG_PATH;
        File output = new File(path);
        if (!output.exists()) {
            output.mkdirs();
        }
        return path;
    }

    public static String getPhotoTargetPath() {
        String path = getCacheRoot() + PHOTO_TARGET_PATH;
        File output = new File(path);
        if (!output.exists()) {
            output.mkdirs();
        }
        return path;
    }

    public static String getPhotoDownloadPath() {
        String path = getCacheRoot() + PHOTO_DOWNLOAD_PATH;
        File output = new File(path);
        if (!output.exists()) {
            output.mkdirs();
        }
        return path;
    }
}
